<template>
  <el-dialog title="跟进记录" :close-on-click-modal="false" :visible.sync="visible">
    <el-table :data="dataList" border v-loading="dataListLoading" style="width: 100%;">
      <el-table-column prop="studentName" header-align="center" align="center" label="学员姓名">
      </el-table-column>
      <el-table-column prop="studentId" header-align="center" align="center" label="学员ID">
      </el-table-column>
      <el-table-column prop="parentPhone" :formatter="parentPhoneFormatter" header-align="center" align="center" label="手机号">
      </el-table-column>
      <el-table-column prop="createAt" header-align="center" align="center" label="预约跟进时间">
      </el-table-column>
      <el-table-column prop="followMode" :formatter="followModeFormatter" header-align="center" align="center" label="跟进方式">
      </el-table-column>
      <el-table-column prop="studentStage" :formatter="studentStageFormatter" header-align="center" align="center" label="学员阶段">
      </el-table-column>
      <el-table-column prop="followRemarks" header-align="center" align="center" label="跟进说明">
      </el-table-column>
    </el-table>
    <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        dataForm: {
          key: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        visible: false
      }
    },
    methods: {
      // 获取数据列表
      getDataList (studentId) {
        console.log(studentId)
        this.dataListLoading = true
        this.visible = true
        this.$http({
          url: this.$http.adornUrl('/generator/studentmanagefollow/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'studentId': studentId
          })
        }).then(({
          data
        }) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 格式化手机号
      parentPhoneFormatter (row, column) {
        return row.parentPhone.replace(/^(.{3}).*(.{4})/, '$1****$2')
      },
      // 格式化学员阶段
      studentStageFormatter (row, column) {
        let studentStage = row.studentStage
        if (studentStage === 0) {
          return '意向学员'
        } else if (studentStage === 1) {
          return '试听学员'
        } else if (studentStage === 2) {
          return '正式学员'
        } else {
          return ''
        }
      },
      // 格式化跟进方式
      followModeFormatter (row, column) {
        let followMode = row.followMode
        if (followMode === 0) {
          return '电话跟进'
        } else if (followMode === 1) {
          return '微信跟进'
        } else if (followMode === 2) {
          return 'QQ跟进'
        } else if (followMode === 3) {
          return '邮件跟进'
        } else if (followMode === 4) {
          return '面谈'
        } else if (followMode === 5) {
          return '其他方式'
        }
      }
    }
  }
</script>
